package com.dlc.shop.systemtest.data.amount;

import com.dlc.shop.bean.app.dto.DvyTypeDTO;
import com.dlc.shop.bean.app.dto.OrderSelfStationDto;
import com.dlc.shop.bean.app.param.*;
import com.dlc.shop.bean.model.Order;
import com.dlc.shop.bean.model.OrderItem;
import com.dlc.shop.bean.model.Station;
import com.dlc.shop.seckill.api.param.SeckillOrderParam;
import com.dlc.shop.systemtest.api.amount.AddrApi;
import com.dlc.shop.systemtest.api.amount.ProductApi;
import com.dlc.shop.systemtest.api.order.ShopStationApi;
import com.dlc.shop.systemtest.api.order.StationApi;
import com.dlc.shop.systemtest.data.order.ShopStationData;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author lanhai
 * 订单测试数据
 */
public class OrderData {
    public static SubmitOrderParam getSubmitOrderParam(List<Long> shopIds){
        SubmitOrderParam submitOrderParam = new SubmitOrderParam();
        ArrayList<OrderShopParam> orderShopParams = new ArrayList<>();
        for (Long shopId : shopIds) {
            OrderShopParam orderShopParam = new OrderShopParam();
            orderShopParam.setRemarks("");
            orderShopParam.setShopId(shopId);
            orderShopParams.add(orderShopParam);
        }

        OrderFlowLogParam orderFlowLogParam = new OrderFlowLogParam();
        orderFlowLogParam.setStep(13);
        orderFlowLogParam.setSystemType(2);
        orderFlowLogParam.setVisitType(1);

        submitOrderParam.setOrderFlowLogParam(orderFlowLogParam);
        submitOrderParam.setOrderShopParams(orderShopParams);
        submitOrderParam.setOrderInvoiceList(null);
        submitOrderParam.setVirtualRemarkList(null);
        return submitOrderParam;
    }

    public static SubmitOrderParam getPickUpSubmitOrderParam(List<Long> shopIds){
        SubmitOrderParam submitOrderParam = new SubmitOrderParam();
        ArrayList<OrderShopParam> orderShopParams = new ArrayList<>();
        for (Long shopId : shopIds) {
            OrderShopParam orderShopParam = new OrderShopParam();
            orderShopParam.setRemarks("");
            orderShopParam.setShopId(shopId);
            orderShopParams.add(orderShopParam);
            //如果没有门店，添加门店
            if(StationApi.getStationList(shopId).isEmpty()){
                Station station = ShopStationData.getShopStationList();
                ShopStationApi.addStation(station);
            }
        }

        OrderFlowLogParam orderFlowLogParam = new OrderFlowLogParam();
        orderFlowLogParam.setStep(13);
        orderFlowLogParam.setSystemType(2);
        orderFlowLogParam.setVisitType(1);

        //查询门店信息和收件人信息
        Station station = new Station();
        station.setStationId(StationApi.getStationList(shopIds.get(0)).get(0).getStationId());
        OrderSelfStationDto orderSelfStationDto = new OrderSelfStationDto();
        orderSelfStationDto.setStationId(station.getStationId());
        orderSelfStationDto.setStationUserMobile(AddrApi.dvyList().get(0).getMobile());
        orderSelfStationDto.setStationUserName(AddrApi.dvyList().get(0).getReceiver());
        submitOrderParam.setOrderShopParams(orderShopParams);
        submitOrderParam.setOrderSelfStationDto(orderSelfStationDto);
        submitOrderParam.setOrderInvoiceList(null);
        submitOrderParam.setVirtualRemarkList(null);
        submitOrderParam.setOrderFlowLogParam(orderFlowLogParam);
        return submitOrderParam;
    }
    public static OrderParam getOrderParam(Long prodId, Integer prodCount, Long addrId, Long userUseScore, String distributionCardNo) {
        OrderParam orderParam = new OrderParam();
        List<Long> list = new ArrayList<>();
        orderParam.setCouponIds(null);
        orderParam.setCouponUserIds(null);
        orderParam.setIsScorePay(Objects.isNull(userUseScore) ? 0 : 1);
        orderParam.setUserChangeCoupon(1);
        orderParam.setUserUseScore(Objects.isNull(userUseScore) ? 0L : userUseScore);
        orderParam.setAddrId(addrId);
        orderParam.setDvyTypes(Arrays.asList(new DvyTypeDTO(userUseScore, 1)));
        if(prodId!=null&&prodCount!=null){
            orderParam.setOrderItem(OrderItemData.getOrderItemParam(prodId,prodCount));
            orderParam.getOrderItem().setDistributionCardNo(distributionCardNo);
        }
        return orderParam;
    }

    public static OrderParam getOrderParam(Long prodId, Integer prodCount, Long addrId, Long userUseScore, String distributionCardNo, Long shopId) {
        OrderParam orderParam = new OrderParam();
        List<Long> list = new ArrayList<>();
        orderParam.setCouponIds(null);
        orderParam.setCouponUserIds(null);
        orderParam.setIsScorePay(Objects.isNull(userUseScore) ? 0 : 1);
        orderParam.setUserChangeCoupon(1);
        orderParam.setUserUseScore(Objects.isNull(userUseScore) ? 0L : userUseScore);
        orderParam.setAddrId(addrId);
        List<DvyTypeDTO> dvyTypeDTOList = new ArrayList<>();
        DvyTypeDTO  dvyTypeDTO = new DvyTypeDTO();
        dvyTypeDTO.setDvyType(1);
        dvyTypeDTO.setShopId(shopId);
        dvyTypeDTOList.add(dvyTypeDTO);
        orderParam.setDvyTypes(dvyTypeDTOList);
        if(prodId!=null&&prodCount!=null){
            orderParam.setOrderItem(OrderItemData.getOrderItemParam(prodId,prodCount));
            orderParam.getOrderItem().setDistributionCardNo(distributionCardNo);
        }
        return orderParam;
    }

    public static OrderParam getPichUpOrderParam(Long prodId, Integer prodCount, Long addrId, Long userUseScore, String distributionCardNo,Long shopId) {
        OrderParam orderParam = new OrderParam();
        orderParam.setCouponIds(null);
        orderParam.setCouponUserIds(null);
        List<DvyTypeDTO> dvyTypeDTOList = new ArrayList<>();
        DvyTypeDTO  dvyTypeDTO = new DvyTypeDTO();
        dvyTypeDTO.setDvyType(2);
        dvyTypeDTO.setShopId(shopId);
        dvyTypeDTOList.add(dvyTypeDTO);
        orderParam.setDvyTypes(dvyTypeDTOList);
        orderParam.setIsScorePay(Objects.isNull(userUseScore) ? 0 : 1);
        orderParam.setUserChangeCoupon(0);
        orderParam.setUserUseScore(Objects.isNull(userUseScore) ? 0L : userUseScore);
        orderParam.setAddrId(addrId);
        if(prodId!=null&&prodCount!=null){
            orderParam.setOrderItem(OrderItemData.getOrderItemParam(prodId,prodCount));
            orderParam.getOrderItem().setDistributionCardNo(distributionCardNo);
        }
        return orderParam;
    }
    /**
     * 分销商品下单参数
     * @param prodId
     * @param prodCount
     * @param addrId
     * @return
     */
    public static OrderParam getOrderDistributionParam(Long prodId, Integer prodCount,Long addrId,String distributionCardNo) {
        OrderParam orderParam = new OrderParam();
        orderParam.setCouponIds(null);
        orderParam.setCouponUserIds(null);
        orderParam.setIsScorePay(0);
        orderParam.setUserChangeCoupon(0);
        orderParam.setUserUseScore(0L);
        orderParam.setAddrId(addrId);
        if(prodId!=null&&prodCount!=null){
            orderParam.setOrderItem(OrderItemData.getOrderItemParam(prodId,prodCount));
            orderParam.getOrderItem().setDistributionCardNo(distributionCardNo);
        }
        return orderParam;
    }

    public static Order getShopChangeAmountOrderParam(Double chageAmount, String orderNumber,
                                                      Double actualTotal, Long orderItemId, Double freightAmount, Long orderId){
        Order order = new Order();
        OrderItem orderItem = new OrderItem();
        orderItem.setActualTotal(actualTotal);
        orderItem.setChageAmount(chageAmount);
        orderItem.setOrderItemId(orderItemId);
        order.setOrderNumber(orderNumber);
        order.setOrderItems(Arrays.asList(orderItem));
        order.setFreightAmount(freightAmount);
        order.setOrderId(orderId);
        return order;

    }

    /**
     * 秒杀商品下单参数
     */
    public static SeckillOrderParam getSeckillOrderParam(Long prodId, Integer prodCount, Long shopId, Long seckillSkuId) {
        SeckillOrderParam seckillOrderParam = new SeckillOrderParam();
        seckillOrderParam.setCouponIds(null);
        seckillOrderParam.setCouponUserIds(null);
        seckillOrderParam.setIsScorePay(0);
        seckillOrderParam.setUserUseScore(0L);
        seckillOrderParam.setAddrId(0L);
        seckillOrderParam.setUserChangeCoupon(0);
        seckillOrderParam.setOrderItem(OrderItemData.getOrderItemParam(prodId, prodCount));
        seckillOrderParam.setSeckillSkuId(seckillSkuId);
        List<DvyTypeDTO> dvyTypes = new ArrayList<>();
        DvyTypeDTO deyType = new DvyTypeDTO();
        deyType.setDvyType(1);
        deyType.setShopId(shopId);
        dvyTypes.add(deyType);
        seckillOrderParam.setDvyTypes(dvyTypes);

        return seckillOrderParam;
    }

    /**
     * 秒杀商品提交订单参数
     */
    public static SubmitSeckillOrderParam getSubmitSeckillOrderParam(Long shopId) {
        SubmitSeckillOrderParam submitSeckillOrderParam = new SubmitSeckillOrderParam();
        List<OrderShopParam> orderShopParams = new ArrayList<>();
        OrderShopParam orderShopParam = new OrderShopParam();
        orderShopParam.setShopId(shopId);
        orderShopParams.add(orderShopParam);
        submitSeckillOrderParam.setOrderShopParams(orderShopParams);

        OrderFlowLogParam orderFlowLogParam = new OrderFlowLogParam();
        orderFlowLogParam.setStep(13);
        orderFlowLogParam.setSystemType(2);
        orderFlowLogParam.setVisitType(1);

        submitSeckillOrderParam.setOrderFlowLogParam(orderFlowLogParam);

        return submitSeckillOrderParam;
    }

    /**
     * 套餐下单数据
     */
    public static OrderParam getComboOrderParam(Long shopId, Long comboId, Integer comboNum, Long mainProductId, List<Long> matchingSkuIds) {
        OrderParam orderParam = new OrderParam();
        orderParam.setAddrId(0L);
        orderParam.setCouponIds(null);
        orderParam.setCouponUserIds(null);
        orderParam.setIsScorePay(0);
        orderParam.setUserChangeCoupon(0);
        orderParam.setUserUseScore(0L);

        List<DvyTypeDTO> dvyTypes = new ArrayList<>();
        DvyTypeDTO deyType = new DvyTypeDTO();
        deyType.setDvyType(1);
        deyType.setShopId(shopId);
        dvyTypes.add(deyType);
        orderParam.setDvyTypes(dvyTypes);

        OrderItemParam orderItemParam = new OrderItemParam();
        orderItemParam.setComboId(comboId);
        orderItemParam.setProdCount(comboNum);
        orderItemParam.setProdId(mainProductId);
        orderItemParam.setShopId(shopId);
        orderItemParam.setSkuId(ProductApi.getProdInfo(mainProductId).getSkuList().get(0).getSkuId());
        orderItemParam.setMatchingSkuIds(matchingSkuIds);
        orderParam.setOrderItem(orderItemParam);

        return orderParam;
    }

}
